<div class="layuimini-main">

  <div class="layui-form layuimini-form">
    <form id="play_form">
      <div class="layui-form-item">
        <label class="layui-form-label required">游戏名称</label>
        <div class="layui-input-block">
          <input type="text" name="name" lay-verify="required" lay-reqtext="游戏名不能为空" placeholder="请输入游戏名称" value="" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">游戏分类</label>
        <div class="layui-input-block">
          <input type="text" name="category" placeholder="请输入游戏分类" lay-verify="required" lay-reqtext="游戏分类不能为空" value="" class="layui-input">
        </div>
      </div>
<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label required">电话号码</label>-->
<!--        <div class="layui-input-block">-->
<!--          <input type="number" name="phone" lay-verify="required" lay-reqtext="电话号码不能为空" placeholder="请输入电话号码" value="" class="layui-input">-->
<!--        </div>-->
<!--      </div>-->

<!--      <div class="layui-form-item">-->
<!--        <label class="layui-form-label">球队名称</label>-->
<!--        <div class="layui-input-block">-->
<!--          <input type="text" name="team" lay-verify="required" placeholder="请输入球队名称" lay-reqtext="球队名称不能为空" placeholder="请输入球队名称" value="" class="layui-input">-->
<!--        </div>-->
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label required">游戏等级</label>
        <div class="layui-input-block">
          <input type="number" name="company" lay-verify="required"   lay-reqtext="游戏公司不能为空" placeholder="请输入游戏公司" value="" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认</button>
        </div>
      </div>
    </form>

  </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
          $.ajax({
            type: "POST",
            dataType: "text",
            url: "http://localhost:8081/PlayerManagement_war_exploded/addPlayerServlet",//url
            data: $('#play_form').serialize(),//这个是form表单中的id，jQuery的serialize()方法通过序列化表单值
            success: function (data) {
              if(data=="ok"){
                layer.msg("添加成功");
                // 关闭弹出层
                layer.close(index);
                layer.close(parentIndex);
              }else{
                layer.msg("添加失败");
              }
            }
          });


        });

    });
</script>
